- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
type Tree<T> = T;
function main() {
let a: Tree<TypeOf<1>>;
a = 10;
print(a);
print("done.");
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
type Tree<T> = T;
function main() {
let a: Tree<TypeOf<1>>;
a = 10;
print(a);
print("done.");
}
новый виток развития TypeScript компайлера.
0
for (let i = 0; i < inputs.length; i++) {
inputs[i].addEventListener('input', function() {
for (let i = 0; i < inputs.length; i++) {
console.log(inputs[i].value);
}
});
}
отобразить в консоли значения инпутов (штмл)...
0
function main()
{
let o = { x: 'hi', y: 17 }
const o2 = { ...o };
print(o2.x, o2.y);
}
а ты так можешь говнокодить на С/C++? дамп не дам.. (толку?)
−8
interface ReturnVal {
something(): void;
}
function run(options: { something?(): void }, val: ReturnVal) {
const something = options.something ?? val.something;
something();
}
function main()
{
run ( { something() { print("something"); } }, null );
}
новая кул-фича... аналог ?. но для двух разных данных. если первое не null тогда бери его иначе второе.
−7
let x = 0.1;
let y = 0.2;
let z = x + y
чему равно?
−8
class C
{
val: number;
constructor()
{
this.val = 2;
}
}
function o(val? : C)
{
print(val?.val);
}
function main()
{
o(new C());
o(null);
o();
}
Новый говнокод подоспел.... а как тебе такое слабый ужасный С/C++ ... ты так умеешь?
Результат работы:
C:\temp>C:\dev\TypeScriptCompiler\__build\tsc\bin\tsc.exe --emit=jit --opt --shared-libs=C:\dev\TypeScriptCompiler\__build\tsc\bin\TypeScriptRuntime.dll C:\temp\1.ts
2
0
0
−7
// @strict: true
interface IFace {
cond0: boolean;
cond1?: boolean;
}
function main() {
const a : IFace = { cond0: true };
print (a.cond0);
print (a.cond1 == undefined);
print (a.cond1);
// a.cond1?.value
print("done.");
}
я вам принес новую фичу. называется опциональные поля в interface-ах. а твой с++ умеет так?
0
interface F1 {
a: number;
a2: boolean;
}
interface F2 {
b: string;
b2: number;
}
type t = F1 & F2 & { c: number };
interface t2 extends F1, F2 {
c: number;
}
type tt = { a: boolean };
type tt2 = { b: number };
type tt3 = { c: string };
type r = tt & tt2 & tt3;
function main() {
const f1: F1 = { a: 10.0, a2: true };
print(f1.a, f1.a2);
const f2: F2 = { b: "Hello1", b2: 20.0 };
print(f2.b, f2.b2);
const a: t = { a: 10.0, a2: true, b: "Hello", b2: 20.0, c: 30.0 };
print(a.a, a.a2, a.b, a.b2);
const b: t2 = { a: 10.0, a2: true, b: "Hello", b2: 20.0, c: 30.0 };
print(b.a, b.a2, b.b, b.b2, b.c);
const c: r = { a: true, b: 10.0, c: "Hello" };
print(c.a, c.b, c.c);
print("done.");
}
я вам тут conjunctions наговнокодил.... а нужен дампик?
0
type NetworkLoadingState = {
state: "loading";
};
type NetworkFailedState = {
state: "failed";
code: number;
};
type NetworkSuccessState = {
state: "success";
response: {
title: string;
duration: number;
summary: string;
};
};
type NetworkState =
| NetworkLoadingState
| NetworkFailedState
| NetworkSuccessState;
function logger(state: NetworkState): string {
switch (state.state) {
case "loading":
return "Downloading...";
case "failed":
// The type must be NetworkFailedState here,
// so accessing the `code` field is safe
return `Error ${state.code} downloading`;
case "success":
return `Downloaded ${state.response.title} - ${state.response.summary}`;
default:
return "<error>";
}
}
function main() {
print(logger({ state: "loading" }));
print(logger({ state: "failed", code: 1.0 }));
print(logger({ state: "success", response: { title: "title", duration: 10.0, summary: "summary" } }));
print(logger({ state: "???" }));
print("done.");
}
Ура... радуйтесь.... я вам еще говнокодца поднадкинул... ну и перекопал же говна в коде что бы это сделать. Дампик тут.. https://pastebin.com/u7XZ00LV Прикольно получается если скомпилить с оптимизацией то нихрена от кода не остается. и результат работы
C:\temp\MLIR_to_exe>1.exe
Downloading...
Error 1 downloading
Downloaded title - summary
<error>
done.
+1
function main() {
let a: number | string;
a = "Hello";
if (typeof(a) == "string")
{
print("str val:", a);
}
a = 10.0;
if (typeof(a) == "number")
{
print("num val:", a);
}
print("done")
}
Аллилуйя братья... я вам принес "union"-s . Возрадуйтесь новой фиче. (А ты можешь так в с/c++?)
дампик https://pastebin.com/QNmKFfT7
C:\temp>C:\dev\TypeScriptCompiler\__build\tsc\bin\tsc.exe --emit=jit --opt --shared-libs=C:\dev\TypeScriptCompiler\__build\tsc\bin\TypeScriptRuntime.dll C:\temp\1.ts
str val: Hello
num val: 10
done