In my JavaScript component, I have a simple exporting statement:
./component/index.js :
export const t = 'string value';
This component also has a TypeScript definition file:
./component/index.d.ts :
export const t: number;
A very basic TypeScript/React project is using this component:
./demo/index.tsx :
import React from 'react';
import ReactDOM from 'react-dom';
import { t } from '../component';
ReactDOM.render(<>{ t }</>, document.getElementById('app'));
Expected outcome: A TypeScript error should be triggered indicating that the value of 't' is expected to be a number but is actually receiving a string instead.
Actual result: No errors or warnings are shown by TypeScript.
You can find a small project reproducing this issue here. I aimed to keep it as minimal as possible. To reproduce:
git clone <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="56313f2216313f223e23347835393b">[email protected]</a>:omatviiv/ts-definition-file-test.git
npm i
npm run dev
I have referred to the official documentation, but it doesn't provide a solution (the examples use '12' for numeric type which adds confusion). The provided example in the Playground also does not seem applicable to this scenario.