-
This following code: type TupleOf<T, N extends number> = N extends N ? (number extends N ? T[] : _TupleOf<T, N, []>) : never;
type _TupleOf<T, N extends number, R extends unknown[]> = R["length"] extends N ? R : _TupleOf<T, N, [T, ...R]>;
type ThreeStrings = TupleOf<string,3>
const threeStrings = ['one', 'two', 'three'] works in the TS Playground and shows no error in vscode but it creates errors when ts-node is run:
Is there an easy explanation to that behavior? |
Beta Was this translation helpful? Give feedback.
Answered by
cspotcode
May 27, 2021
Replies: 2 comments 4 replies
-
Do the versions match? Does the behavior change with |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
cspotcode
-
Thanks for the suggestions. How are the versions supposed to match? Here is what I get:
And {
diagnostics: [
{
file: [SourceFileObject],
start: 345,
length: 18,
messageText: "Type '_TupleOf' is not generic.",
category: 1,
code: 2315,
reportsUnnecessary: undefined,
reportsDeprecated: undefined
},
{
file: [SourceFileObject],
start: 379,
length: 8,
messageText: "Type alias '_TupleOf' circularly references itself.",
category: 1,
code: 2456,
reportsUnnecessary: undefined,
reportsDeprecated: undefined
},
{
file: [SourceFileObject],
start: 460,
length: 25,
messageText: "Type '_TupleOf' is not generic.",
category: 1,
code: 2315,
reportsUnnecessary: undefined,
reportsDeprecated: undefined
}
]
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do the versions match?
ts-node -vv
?Does the behavior change with
ts-node --files
enabled?