TypeScript combining *.js + *.d.ts again?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


TypeScript combining *.js + *.d.ts again?



TypeScript tsc -d "declaration" of "compilerOptions" generates corresponding '.d.ts' file.


tsc -d



For instance, from:


const log = (m: unknown) => {
console.log((m));
return m;
};



it generates:


const log = (m) => {
console.log((m));
return m;
};



and:


declare const log: (m: unknown) => unknown;



I think this is quite interesting because it "devides" the TypeScript source code to a native JavaScript code and the extra type definition.



Then, here is my thought. After deviding the native code and type definition, is it easily possilbe to generate a valid TypeScript code by re-binding both codes.



For instance:


declare const log1: (m: unknown) => unknown;

const log1 = m => {
console.log((m));
return m;
};



This code generates an errors:


[ts] Cannot redeclare block-scoped variable 'log1'.



for each statements.



Why am I tring this?



I'm motivated by facts:



In Algebra,



(x^2 + 3x +2) = (x+1)(x+2) = (x^2 + 3x +2)



I want to confirm if the same thing is valid under TypeScript.



The fact makes me think, in a sense, the output of the vanilla JS code is type safe and valid with TypeScirpt, just without the *.d.ts file which is eventually appearently merely an extra helper functionality that TypeScript compiler takes advantage of. It's just a tool.



Accordingly, the type-safty of the vanilla JS code can be later, easily validated by TypeScript compiler with the helper functional tool, that is tmp.d.ts. That is what I want to confirm.


tmp.d.ts



Thanks.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Future solutions